// JointPortMatchFunction.cpp: implementation of the JointPortMatchFunction class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "phsshare.h"
#include "JointPortMatchFunction.h"
#include "Joint.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

IMPLEMENT_DYNAMIC_CREATE(JointPortMatchFunction, JointOwnFunction, FunctionObject::eJOINTMATCHFUNCTION);
JointPortMatchFunction::JointPortMatchFunction()
{

}

JointPortMatchFunction::~JointPortMatchFunction()
{

}

FunctionObject* JointPortMatchFunction::InstanceFunction(Joint* pJoint)
{
	JointPortMatchFunction* pFun = new JointPortMatchFunction;
	for(int i = 0; i < m_strExprFormerArray.GetSize(); i++)
	{
		pFun->m_strExprArray.Add(CaculateString(
			m_strExprFormerArray.GetAt(i), pJoint->GetPropertyStack()));
	}
	pFun->SetOwner(pJoint);
	pJoint->AttachFunction(pFun);

	return pFun;
}

BOOL JointPortMatchFunction::Execute()
{
	for(int i = 0; i < m_strExprArray.GetSize(); i++)
	{
		if(atoi(CaculateString(m_strExprArray.GetAt(i))) == 0)
			return FALSE;
	}
	return TRUE;
}